package com.scau402.common.utils;


import com.alibaba.fastjson2.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

public class ApiUtils {

    private RestTemplate restTemplate = null;

    public ApiUtils() {
        this.restTemplate = restTemplate;
    }

    public String postApi(JSONObject params, String url) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<String> request = new HttpEntity<>(params.toJSONString(), headers);
        return restTemplate.postForObject(url, request, String.class);
    }

}
